package com.zxx.order.service.repository

import com.zqq.baselibrary.http.RetrofitFactory
import com.zqq.baselibrary.http.rx.BaseResp
import com.zxx.order.service.api.ShipAddressApi
import com.zxx.order.service.bean.AddShipAddressReq
import com.zxx.order.service.bean.DeleteShipAddressReq
import com.zxx.order.service.bean.EditShipAddressReq
import com.zxx.order.service.bean.ShipAddress
import rx.Observable
import javax.inject.Inject

/**
 * 收货地址数据层
 * wc
 * @author zqq on 2019/6/30.
 */
class ShipAddressRepository @Inject constructor() {

    /*
       添加收货地址
    */
    fun addShipAddress(shipUserName: String, shipUserMobile: String, shipAddress: String): Observable<BaseResp<String>> {
        return RetrofitFactory.instance
                .create(ShipAddressApi::class.java)
                .addShipAddress(AddShipAddressReq(shipUserName, shipUserMobile, shipAddress))
    }

    /*
        删除收货地址
     */
    fun deleteShipAddress(id: Int): Observable<BaseResp<String>> {
        return RetrofitFactory.instance
                .create(ShipAddressApi::class.java)
                .deleteShipAddress(DeleteShipAddressReq(id))
    }

    /*
        修改收货地址
     */
    fun editShipAddress(address: ShipAddress): Observable<BaseResp<String>> {
        return RetrofitFactory.instance
                .create(ShipAddressApi::class.java)
                .editShipAddress(EditShipAddressReq(address.id, address.shipUserName, address.shipUserMobile, address.shipAddress, address.shipIsDefault))
    }

    /*
        获取收货地址列表
     */
    fun getShipAddressList(): Observable<BaseResp<MutableList<ShipAddress>?>> {
        return RetrofitFactory.instance
                .create(ShipAddressApi::class.java)
                .getShipAddressList()
    }

}